import { defineStore } from "pinia";
import router from "../routers";
import { useUsersStore } from "./usersStore";

interface State{
    
    token:string | null,
    isLoading:boolean
}

export const useStatusStore = defineStore('status',{
    state:():State=>{
        return{
            token:localStorage.getItem('token'),
            isLoading:false
        }
    },

    getters:{

    },

    actions:{
        SetToken(token:string){
            this.token=token
            if(token){
                localStorage.setItem('token',token)
            }
            else{
                localStorage.removeItem('token')
            }
        },

        LogOut(){
            localStorage.removeItem('userInfo');
            localStorage.removeItem('token');
            useUsersStore().currentUser=null;
            this.token=null;
            router.push('login');
        }
    }
})

